home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / TEXTEDIT.SWG / 0013_Word Wrap.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-25  |  2KB  |  67 lines

  1. {
  2. BT>Hello All...
  3.  
  4. BT>       Ok once again I have reached a brick wall in my program... What I
  5. BT>was trying to do, was to make Word Wrap actully work... Turns out I was
  6. BT>barking up the wrong tree... If you have examples on how to do this... Th
  7. BT>please reply
  8. BT>and let me know...
  9.  
  10. What I'm about to describe assumes you either have a loop of
  11. procedure/function that'll read in one line as it works on a line by
  12. line basis....  What I've always done (for wordwrap) is when entering a
  13. line, it stores each character into a holding string that'll contain the
  14. final line, you also have a string that contains the wrapped text, if
  15. the user presses space, you clear the string holding the wrapped text,
  16. and if they reach the end of the line, you erase as many characters as
  17. the length of the string holding the wrapped text...
  18.  
  19. Example (untested):
  20.  
  21. (uses the CRT unit)
  22. }
  23.  
  24. Procedure GetLineWithWrap(var Line,Wrap: String);
  25. Const Cr=#13;
  26.       BS=#8;
  27.       EraseChar=#8+#32+#8;
  28.  
  29. Var HoldLine,HoldWrap: String;
  30.     Ch: Char;
  31.     Count: Byte;
  32.  
  33. Begin
  34.      HoldWrap:='';
  35.      HoldLine:='';
  36.      if length(line)<>0 then begin
  37.         HoldLine:=Line;
  38.         Write(Line) end;
  39.      Repeat
  40.         While not keypressed do;
  41.         Ch:=Readkey;
  42.         If WhereX=80 and then begin
  43.            For Count:=1 to Length(HoldWrap) Write(EraseChar);
  44.            HoldLine:=Copy(HoldLine,1,Length(HoldLine)-Length(HoldWrap)-1);
  45.            Line:=HoldLine;
  46.            If Ch=#32 then Wrap:='' else Wrap:=HoldWrap+ch;
  47.            Exit End;
  48.         Case Ch of
  49.             #13 : {nothing, but don't want it added to the line};
  50.              #8 : If length(HoldLine)>0 then begin
  51.                      Write(EraseChar);
  52.                      If Length(HoldLine)>1 then
  53.                        HoldLine:=Copy(HoldLine,1,Length(HoldLine)-1)
  54.                        else HoldLine:='';
  55.                      If Length(HoldWrap)>1 then
  56.                        HoldWrap:=Copy(HoldWrap,1,Length(HoldWrap)-1)
  57.                        else HoldWrap:='';
  58.                    End;
  59.              #32 : Begin
  60.                 HoldLine:=HoldLine+' ';
  61.                 HoldWrap:='' end;
  62.         Else HoldLine:=HoldLine+Ch End;
  63.     Until Ch=#13;
  64.     Line:=HoldLine;
  65.     Wrap:='';
  66.     End;
  67.